//Registartion Form
function userRegistrationForm(){
   	var flag=true;
	var phoneno 		= /^\d{10}$/; 
	var charactervalidation = /^[a-zA-Z\s]*$/;
	var username		=	$('#user_name').val();
	var useremail		=	$('#user_email').val();
	var userpassword	=	$('#user_password').val();
	var mobile			= 	$('#user_mobile').val();
	if(username==""){
		$('#user_nameError').html("Required");
		flag=false;
	}else if(!username.match(charactervalidation)){
		$('#user_nameError').html("Characters only");
		flag=false;
	}else{
		$('#user_nameError').html('');
	}
	
	if(useremail==""){
	   $("#user_emailError").html("Required");
	   flag=false;   
	}else{
	    if(validateEmail(useremail)==0){
		  $("#user_emailError").html("In Valid Email");
		  flag=false; 
	    }else{
			  $("#user_emailError").html(""); 
			}
	} 
	
	if(userpassword==""){
	   $("#user_passwordError").html("Required");
	   flag=false;   
	}else{
	    $("#user_passwordError").html(""); 
	} 
	
	if(mobile==""){
		$('#user_mobileError').html("Required");
		flag=false;
	}else if(isNaN(mobile)){
		$('#user_mobileError').html("Numbers only");
		flag=false;
	}else if(!mobile.match(phoneno)){
		$('#user_mobileError').html("Invalid phonenumber");
		flag=false;
	}else{
		$('#user_mobileError').html('');
	}
	if(flag==true){
		$('#registrationLoader').html('<img src="images/ajax-loader.gif"/>');
		$.ajax({
			type		:	'POST',
			url			:  	webServiceUrl+'registration',
			dataType	: 	"json",
			data		:	{admin_id:'0', user_name:username,user_email:useremail,user_password:userpassword,user_mobile:mobile, user_type_id:2,hid_user_id:'0'},
			success: function(data){
				$('#registrationLoader').html('');
				if(data.value==1){
					$('#user_emailError').html("");
					localStorage.setItem( 'user_id', JSON.stringify(data.UserId));			
					localStorage.setItem( 'user_email', JSON.stringify($('#user_email').val()));		
					window.location="register-confirmation.html";
				}else{
					$('#registrationLoader').html('');
					$('#user_emailError').html(data.data);
				}
			}
		});
	}
}
//Check Email validation
function emailValidation(){
	var user_email=$('#user_email').val();
	if(user_email!==''){
		if(validateEmail(user_email)==0)
		{
			$('#user_emailError').html("In Valid email");		
		}else{	
			$.ajax({
				type		:	'GET',
				url			:  	webServiceUrl+'login/'+user_email,
				dataType	: 	"json",
				success: function(data){
					if(data.value==1){
						$('#user_emailError').html(data.data);
						return false;
					}else{
						$('#user_emailError').html("");
					}
				}
			});
		}
  }
}

//End

//Login Form
function userLoginForm(){
   	var flag=true;
	
	var useremail		=	$('#user_email').val();
	var userpassword	=	$('#user_password').val();
	
	if(useremail==""){
	   $("#user_emailError").html("Required");
	   flag=false;   
	}else{
	    if(validateEmail(useremail)==0){
		  $("#user_emailError").html("In Valid Email");
		  flag=false; 
	    }else{
			  $("#user_emailError").html(""); 
			}
	}
	
	if(userpassword==""){
	   $("#user_passwordError").html("Required");
	   flag=false;   
	}else{
	    $("#user_passwordError").html(""); 
	} 
	if(flag==true){
		$('#loginError').html("");
		$('#loginloader').html('<img src="images/ajax-loader.gif"/>');
		$.ajax({
			type		:	'POST',
			url			:  	webServiceUrl+'login',
			dataType	: 	"json",
			data		:	{user_email:useremail,user_password:userpassword,user_type_id:'2'},
			success: function(data){
				if(data.value==1){	
					$('#loginError').html("");
					localStorage.setItem( 'user_id', JSON.stringify(data.userData));			
					localStorage.setItem( 'user_email', JSON.stringify($('#user_email').val()));
					window.location="menu.html";
				}else{
					$('#loginloader').html('');
					$('#loginError').html("UserName/Password is wrong");
				}
			}
		});
	}
}
//Forget Password 

function forgetpasswordForm(){
    var flag=true;
	var user_email=$('#user_email').val();
	
	if(user_email==""){
	   $("#user_emailError").html("Required");
	   flag=false;   
	}else{
	    if(validateEmail(user_email)==0){
		  $("#user_emailError").html("In Valid email");
		  flag=false; 
	    }else{
			  $("#user_emailError").html(""); 
			}
	}
	
	if(flag==true){
	   $('#successfpassword').html('');
	   $('#forgotpasswordLoader').html('<img src="images/ajax-loader.gif"/>');
	   
	   $.ajax({
			type		:	'POST',
			url			:  	webServiceUrl+'forgetpassword',
			dataType	: 	"json",
			data		:	{
								user_email:user_email
							},
			success: function(data){
			$('#forgotpasswordLoader').html('');
				if(data.value==1){
					$('#successfpassword').html(data.message);
				}else{
					$('#successfpassword').html(data.message);
				}
			}
		});
	}
}
//Reset password

function resetpasswordFunction(){
  var flag=true;
  var Resetpassword=$("#resetPassword").val();
  var Confirmpassword=$("#Confirmpassword").val();
    if(Resetpassword==""){
      $("#resetPasswordError").html("Required");
	  flag=false;
	}else{
      $("#resetPasswordError").html("");
	}
	
	if(Confirmpassword==""){
        $("#ConfirmpasswordError").html("Required");
		flag=false;
	}else if(Resetpassword!=Confirmpassword){
	   $("#ConfirmpasswordError").html("Not match");
	   flag=false;
	}else{
       $("#ConfirmpasswordError").html("");
	}
	
	if(flag==true){
	   var path = window.location.href;
	   path = path.replace(/\/$/, "");
	   path = decodeURIComponent(path);
       var id=path.split('=');
       var token=id[1];
	    $('#SuccessReset').html("");
	    $('#resetpasswordLoader').html('<img src="images/ajax-loader.gif"/>');
	    $.ajax({
				type		:	'PUT',
				url			:  	webServiceUrl+'forgetpassword/'+token,
				dataType	: 	"json",
				data        : {cnf_password:Confirmpassword},
				success: function(data){
					$('#resetpasswordLoader').html('');
					if(data.value==1){
						$('#SuccessReset').html("Your password Update");
					}else{
						$('#SuccessReset').html("Already update your password please login.");
					}
				}
		});
	}
}

// Email validation

function validateEmail(emailValue){
var emailvalidation = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   if(!emailvalidation.test(emailValue)){
     return 0;
    }else{
      return 1;
    }
}

function logoutFunction(){
	localStorage.removeItem("user_id");
	localStorage.removeItem("user_email");
	window.location="index.html";
}

function technologyGamesFunction(type){
	window.location="technologygames.html";
}
function interviewQuestionsFunction(type){
	window.location="interviewquestions.html";
}
function hotjobsFunction(type){
	window.location="hotjobs.html";
}
function courseFunction(){
	window.location="technology.html";
}

function aboutCourseFunction(type){
var technology_id=$('#hid_tech_id').val();
	if(type==0){
		window.location="course-description.html?id="+technology_id;
	}else if(type==1){
		window.location="course-request.html?id="+technology_id;
	}else if(type==2){
		window.location="course-training-info.html?id="+technology_id;
	}else{
		window.location="course-structure.html?id="+technology_id;
	}	
}

//Redirect Url Register

function joinFunction(){
	window.location="registration.html";
}

//Cousre Detailes Form

function CourseInfoFunction(){
	var flag=true;
	var phoneno 		= /^\d{10}$/; 
	var charactervalidation = /^[a-zA-Z\s]*$/;
	var courses			=	$('#technology').val();
	var cdetailes		=	$('#courseDetailes').val();
	var startDate		=	$('#start').val();
	var endDate			=	$('#finish').val();
	var userfname		=	$('#fname').val();
	var userlname		=	$('#lname').val();
	var useremail		=	$('#email').val();
	var mobile			= 	$('#phone').val(); 
	var country			=	$('#country').val();
	var city			=	$('#city').val();
	var postcode		=	$('#code').val();
	var address			=	$('#address').val();
	var addressinfo		=	$('#info').val();
	if(courses==""){
		$('#technologyError').html("Required");
		 flag=false;   
	}else{
		$('#technologyError').html("");
	}
	if(cdetailes==""){
		$('#courseError').html("Required");
		 flag=false;   
	}else{
		$('#courseError').html("");
	}
	if(startDate==""){
		$('#startError').html("Required");
		 flag=false;   
	}else{
		$('#startError').html("");
	}
	if(endDate==""){
		$('#finishError').html("Required");
		 flag=false;   
	}else{
		$('#finishError').html("");
	}
	if(userfname==""){
		$('#fnameError').html("Required");
		 flag=false;   
	}else{
		$('#fnameError').html("");
	}
	if(userlname==""){
		$('#lnameError').html("Required");
		 flag=false;   
	}else{
		$('#lnameError').html("");
	}
	if(useremail==""){
	   $("#emailError").html("Required");
	   flag=false;   
	}else{
	    if(validateEmail(useremail)==0){
		  $("#emailError").html("In Valid Email");
		  flag=false; 
	    }else{
			  $("#emailError").html(""); 
			}
	} 
	if(mobile==""){
		$('#phoneError').html("Required");
		 flag=false;   
	}else if(isNaN(mobile)){
		$('#phoneError').html("Numbers only");
		 flag=false;   
	}else{
		$('#phoneError').html("");
	}
	if(country==null){
		$('#countryError').html("Required");
		 flag=false;   
	}else{
		$('#countryError').html("");
	}
	if(city==""){
		$('#cityError').html("Required");
		 flag=false;   
	}else{
		$('#cityError').html("");
	}
	if(postcode==""){
		$('#codeError').html("Required");
		 flag=false;   
	}else{
		$('#codeError').html("");
	}
	if(address==""){
		$('#addressError').html("Required");
		 flag=false;   
	}else{
		$('#addressError').html("");
	}
	if(addressinfo==""){
		$('#infoError').html("Required");
		 flag=false;   
	}else{
		$('#infoError').html("");
	}
	if(flag==true){
	 $('#contactloader').html('<img src="images/ajax-loader.gif"/>');
		 $.ajax({
			type		:	'POST',
			url			:  	webServiceUrl+'Contact',
			dataType	: 	"json",
			data        : {course_name:courses,course_detailes:cdetailes,firstname:userfname,lastname:userlname,email:useremail,phonenumber:mobile,country:country,city:city,postcode:postcode,address:address,addressinfo:addressinfo,startdate:startDate,enddate:endDate},
			success: function(data){
				$('#contactloader').html('');
				if(data.value==1){
					$('#technology').val('');
					$('#courseDetailes').val('');
					$('#start').val('');
					$('#finish').val('');
					$('#fname').val('');
					$('#lname').val('');
					$('#email').val('');
					$('#phone').val(''); 
					$('#country').val('');
					$('#city').val('');
					$('#code').val('');
					$('#address').val('');
					$('#info').val('');
					$('#contacsuccess').html("Successfully Sent");
				}
			}
		});
	}
}

function backFunction(type){
	if(type==0){
		window.location="index.html";
	}else{
		window.location="menu.html";
	}
	
}
//Contact form 
function ContactformFunction(con_id){
	window.location="contactform.html?id="+con_id;
}

function getContactmenu(){
var contact_id=getParameterByName('id');
var cont_form="";
	if(contact_id==0){
		cont_form+='<li class="color6"><a href="javascript:void(0)" onclick="indmenuActive(0)">HOME</a></li>'+
			'<li class="color3"><a href="javascript:void(0)" onclick="indmenuActive(1)" >Technology Games</a></li>'+
			'<li class="color4"><a href="javascript:void(0)" onclick="indmenuActive(2)" >Courses</a></li>'+
			'<li class="color5"><a href="javascript:void(0)" onclick="indmenuActive(3)" >Hot Jobs</a></li>'+
			'<li class="color2"><a href="javascript:void(0)" onclick="indmenuActive(4)" >Interview Questions </a></li>'+
            '<li class="color1 active"><a href="javascript:void(0)" onclick="ContactformFunction(0)">Contact</a></li>';
		$('#backbutton').html('<button type="button" class="button button-secondary" onclick="backFunction(0)">Back</button>');
		$('#contactlLogo').html('<a href="javascript:void(0);" onclick="logoFunction(0)"><img src="images/vtp-logo.png" width="163" height="127" class="img-responsive logo"></a><div id="hid_logout" style="position:absolute; top:47px; right:90px; display:none;"><button type="button" onclick="logoutFunction()" class="btn btn-danger btn-outline btn-sm">Logout</button></div>');
	}else{
		cont_form+='<li class="color6"><a href="menu.html">HOME</a></li>'+
			'<li class="color3"><a href="technologygames.html">Technology Games</a></li>'+
			'<li class="color4"><a href="technology.html">Courses</a></li>'+
			'<li class="color5"><a href="hotjobs.html" >Hot Jobs</a></li>'+
			'<li class="color2"><a href="interviewquestions.html" >Interview Questions </a></li>'+
            '<li class="color1 active" ><a href="javascript:void(0)" onclick="ContactformFunction(1)">Contact</a></li>';
			$('#backbutton').html('<button type="button" class="button button-secondary" onclick="backFunction(1)">Back</button>');
			$('#contactlLogo').html('<a href="javascript:void(0);" onclick="logoFunction(1)"><img src="images/vtp-logo.png" width="163" height="127" class="img-responsive logo"></a><div style="position:absolute; top:47px; right:90px;"><button type="button" onclick="logoutFunction()" class="btn btn-danger btn-outline btn-sm">Logout</button></div>');
	}
	$('#contctform_menu').html(cont_form);
}
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
function logoFunction(logotype){
	if(logotype==0){
		window.location="index.html";
	}else{
		window.location="menu.html";
	}
}

function menuActive(menutype){
	window.location="menu.html?id="+menutype;
}
function indmenuActive(imenutype){
	window.location="index.html?id="+imenutype;
}
function indexmenuAct(){
	var id=getParameterByName('id');
	if(id==1){
		$('.color3').addClass('active');
	}
	if(id==2){
		$('.color4').addClass('active');
	}
	if(id==4){
		$('.color2').addClass('active');
	}
	if(id==3){
		$('.color5').addClass('active');
	}
	if(id==0 || id==""){
		$('.color6').addClass('active');
	}
}
function backCourse(){
	var tech_id=getParameterByName('id');
	window.location="aboutcourse.html?id="+tech_id;
}